#ifndef ELITE_ROBOT_SDK_PARAM_H
#define ELITE_ROBOT_SDK_PARAM_H
#include <string>
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
#include "logger.h"
#include "utils.h"

typedef double Param6D[6];

class EliteRobotSdkParamBase
{
public:
    virtual void set_params() = 0;
    rapidjson::Writer<rapidjson::StringBuffer>* writer=nullptr;
};

//机器人开关状态
enum ELITE_SDK_SWTICH
{
    ELITE_SDK_DISABLE = 0,  //关闭机器人碰撞开关
    ELITE_SDK_ENABLE = 1,   //打开机器人碰撞开关
    ELITE_SDK_COL_UNKNOW
};

//机器人碰撞使能参数
class EliteColEnable:public EliteRobotSdkParamBase
{
public:
    void set_params();
    int enable;
};

//机器人运行速度参数
class EliteSpeedValue:public EliteRobotSdkParamBase
{
public:
    void set_params();
    double value;
};

//机器人jbi文件名参数
class EliteJbiFilename:public EliteRobotSdkParamBase
{
public:
    void set_params();
    std::string filename;
};

//机器人设置系统I变量值参数
template <typename T>
class EliteSetSystemVar:public EliteRobotSdkParamBase
{
public:
    void set_params(){
        writer->Key("params");
        writer->StartObject();
        writer->Key("addr");
        writer->Int(addr);
        if(std::is_same<T, int>::value){
            writer->Key("value");
            int *tmp = (int*)&value;
            writer->Int(*tmp);
        }else if(std::is_same<T, double>::value){
            writer->Key("value");
            double *tmp = (double*)&value;
            writer->Double(*tmp);
        }else if(std::is_same<T, Param6D>::value){
            writer->Key("value");
            writer->StartArray();
            double *tmp = (double*)&value;
            for (unsigned i = 0; i < 6; i++)
                writer->Double(tmp[i]);
            writer->EndArray();
        }

        writer->EndObject();
    }
    int addr;
    T value;
};

//机器人获取系统变量值参数
class EliteGetSystemVar:public EliteRobotSdkParamBase
{
public:
    void set_params();
    int addr;
};

//机器人获取系统变量值参数
class EliteSetServoStatus:public EliteRobotSdkParamBase
{
public:
    void set_params();
    int status;
};

//机器人关节运动
class EliteMoveByjoint:public EliteRobotSdkParamBase
{
public:
    void set_params();
    Param6D joint_pos;
    double speed;
};

//机器人关节运动
class EliteInverseKinematic:public EliteRobotSdkParamBase
{
public:
    void set_params();
    Param6D target_pose;
};

//机器人获取Tcp Pose参数
class EliteGetTcpPose:public EliteRobotSdkParamBase
{
public:
    void set_params();
    int unit_type;
};


#endif // ELITE_ROBOT_SDK_PARAM_H
